package com.example.membersteward.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.membersteward.common.CommonResult;
import com.example.membersteward.entity.RoleUser;
import com.example.membersteward.enums.RoleType;
import com.example.membersteward.exception.ServiceException;
import com.example.membersteward.service.RoleUserService;
import com.example.membersteward.mapper.RoleUserMapper;
import com.example.membersteward.util.SecurityUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
* @author 26690
* @description 针对表【role_user(角色与用户关联表)】的数据库操作Service实现
* @createDate 2025-04-08 22:52:37
*/
@Service
public class RoleUserServiceImpl extends ServiceImpl<RoleUserMapper, RoleUser>
    implements RoleUserService{

    @Resource
    RoleUserMapper roleUserMapper;

    @Override
    public CommonResult isAdmin() {
        try {
            Long userId = SecurityUtils.getUserId();
            Integer ret = roleUserMapper.isAdmin(RoleType.ADMIN.getCode(), userId);
            if (ret == null || ret <= 0) {
                return CommonResult.error(403, "非管理员用户不能进行该操作");
            }
            return CommonResult.success();
        }catch (ServiceException e) {
            return CommonResult.error(e.getCode(), e.getMessage());
        }
    }
}




